Attribute VB_Name = "LinkUD"
'=======================================================================
'DDE LINK CONTROL
'   Methods::
'   1: Links Start
'   2: Links Stop
'   3: Links UpDate
'=======================================================================
Option Explicit

'-----------------------------------------------------------------------
'   DDE LINKS START
'-----------------------------------------------------------------------
Sub ddeLinksStart()
    Vdt.LinkRun = True
    On Error Resume Next
    Dim pT
    For pT = 1 To Vdt.Count
        If Not Vdt.Item(pT).Deleted And Vdt.Item(pT).Type <> 3 Then
            Vdt.Link(pT).LinkTimeout = 5
            Vdt.Link(pT).LinkMode = 1
            DoEvents
        End If
    Next
End Sub

'-----------------------------------------------------------------------
'   DDE LINKS STOP
'-----------------------------------------------------------------------
Sub ddeLinksStop()
    On Error Resume Next
    Dim pT
    For pT = 1 To Vdt.Count
        Vdt.Link(pT).LinkMode = vbLinkNone
        DoEvents
    Next
    Vdt.LinkRun = False
End Sub

'-----------------------------------------------------------------------
'   DDE LINK UPDATE
'-----------------------------------------------------------------------
Sub ddeLinkUpDate()
    On Error Resume Next
    Dim pT
    For pT = 1 To Vdt.Count
        If Vdt.Link(pT).LinkMode = vbLinkAutomatic Then
            Select Case Vdt.Item(pT).Type
                'RAW
                Case 0: Vdt.Disp(pT) = Vdt.Link(pT) & " "
                
                'BINARY ON/OFF
                Case 1:
                    If Vdt.Link(pT) = 1 Then
                        Vdt.Disp(pT) = Vdt.Item(pT).OnState
                        If Vdt.Item(pT).DUseColor = 1 Then Vdt.Disp(pT).BackColor = Vdt.Item(pT).DOnColor
                    Else
                        Vdt.Disp(pT) = Vdt.Item(pT).OffState
                        If Vdt.Item(pT).DUseColor = 1 Then Vdt.Disp(pT).BackColor = Vdt.Item(pT).DOffColor
                    End If
                    If Vdt.Item(pT).DUseColor <> 1 Then Vdt.Disp(pT).BackColor = vbWhite
                    
                'SCALED ANALOG
                Case 2:
                    Vdt.Disp(pT) = Format(Vdt.Link(pT) * Vdt.Item(pT).Scl + Vdt.Item(pT).Offset, "0." & String(Vdt.Item(pT).Round, "0")) & " "
                'LMMI opener
                Case 3:
                    Vdt.Link(pT).LinkMode = vbLinkNone
            End Select
        Else
            If Vdt.Item(pT).Type <> 3 Then
               Vdt.Disp(pT) = "NoLink"
            Else
               Vdt.Disp(pT) = Vdt.Desc(pT)
            End If
        End If
    Next
End Sub
